package com.jikexueyuan.activiti;


import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;

public class TestOne {
	
	public static void main(String[] args) {
		/**
		流程(Process)小结

        1.创建流程图
        	eclipse插件、手动编写xml

		2.上传流程图
   			创建仓库(Repository)来保存流程图
   			流程引擎(ProcessEnginer) <- 流程引擎配置

		3.部署流程图
   			RepositoryService加载流程图,然后部署流程图

		4.启动流程
    		Class Person{
			}
    		Person p = new Person();//创建一个Person类对象，实例
    		ProcessInstance //流程实例
    		Runtime,通过运行时服务(RuntimeService)得到流程实例

		5.处理流程任务
   			任务Task ,通过任务服务(TaskService)去检索待处理的任务
   			handle task*/
		//1.获取流程引擎配置
		ProcessEngineConfiguration config=ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("config/activiti.cfg.xml");
		//2.创建流程引擎
		ProcessEngine engine=config.buildProcessEngine();
		//3.获取RepositoryService
		RepositoryService repositoryService=engine.getRepositoryService();
		//4.部署流程图
		repositoryService.createDeployment().addClasspathResource("process/HelloWorld.bpmn20.xml").deploy();
		//5.获取运行时服务
		RuntimeService runtimeService=engine.getRuntimeService();
		//6.获取流程实例
		String processDefinitionKey="myProcess";
		ProcessInstance instance=runtimeService.startProcessInstanceByKey(processDefinitionKey);
		//7.获取taskService
		TaskService taskService=engine.getTaskService();
		//8.查询taskId
		Task task=taskService.createTaskQuery().singleResult();
		//9.处理任务
		System.out.println(task.getName());
	}
}
